//
//  GQLocationProvinceController.m
//  GuQu
//
//  Created by HELIUM STAR on 15/6/9.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQLocationProvinceController.h"
#import "GQRegisterAreaInfo.h"
#import "GQProvince.h"
#import "GQLocationCityController.h"

@interface GQLocationProvinceController () <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) UITableView *tableView;

@end

@implementation GQLocationProvinceController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.width, self.view.height) style:UITableViewStyleGrouped];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kFlag];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    return [GQRegisterAreaInfo sharedGQRegisterAreaInfo].areaArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kFlag forIndexPath:indexPath];
    if (indexPath.section == 1) {
        GQProvince *province = [GQRegisterAreaInfo sharedGQRegisterAreaInfo].areaArr[indexPath.row];
        cell.textLabel.text = province.provinceValue;
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GQLocationCityController *GQLCC = [[GQLocationCityController alloc] init];
    GQLCC.selectedRow = indexPath.row;
    [self.navigationController pushViewController:GQLCC animated:YES];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"定位到的位置";
    }
    return @"全部";
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 36;
}


@end
